﻿//登录验证
var login = function(userid,password,callback){
	sendRequest("/login",{"userid":userid,"password":password},callback);
};
//验证用户名是否存在
var useridIsExist = function(userid,callback){
	sendRequest("/useridIsExist",{"userid":userid},callback);
};
//注册新的用户
var addUser = function(userid,password,callback){
	sendRequest("/addUser",{"userid":userid,"password":password},callback);
};
//获取日记数据
var getNote = function(userid,callback){
	sendRequest("/getNote",{"userid":userid},callback);
};
//保存日记数据
var saveNote = function(noteID,content,userid,callback){
	sendRequest("/saveNote",{"noteID":noteID,"content":content,"userid":userid},callback);
};
//删除日记数据
var deleteNote = function(noteID,callback){
	sendRequest("/deleteNote",{"noteID":noteID},callback);
};
//获取用户信息
var getUserInfo = function(userid,callback){
	sendRequest("/getUserInfo",{"userid":userid},callback);
};
//保存用户数据
var saveUserInfo = function(userid,username,sex,birthday,phone,email,callback){
	sendRequest("/saveUserInfo",{"userid":userid,"username":username,"sex":sex,"birthday":birthday,"phone":phone,"email":email},callback);
};
//利用ajax跟传出数据
var sendRequest = function(url,data,callback){
	$.ajax({
	"type" : "post",
	"async" : false,
	"dataType" : "json",
	"url" : url,
	"data" : data,
	"complete" : function(xhr) {
		if (xhr.readyState == 4 && xhr.status == 200) {
				callback(JSON.parse(xhr.responseText));
		}else{
			alert('访问出现问题');
		}
	}
});
};
